<!DOCTYPE html>
<html> 
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">

<title>yukari world</title>
    <#include "/lib/base_source.ftl">
      <style type="text/css">
          li {list-style-type:none;}
      </style>
  </head> 
  <body>
    <div class='whole-container'>
      <#include "/lib/header.ftl">
        <div>
          <ul class="breadcrumb">
            <li>弹幕管理</li><span class="divider">/</span>
            <li>弹幕查询</li>
          </ul>
        </div>
        <div class="container-fluid">
          <div class="row-fluid">
            <div class="container span12">
              <#include "/lib/alert.ftl">
                 <div class='main-content'>
                    <div class="well form-horizontal">
                        <div class='main-action'>
                            <form id="searchForm">
                    		<div class="control-group">
                                <label class="control-label">斗鱼ID：</label>
                                <div class="controls">
                                    <input type="text" id="name" name="name" value="" />
                                </div>
                            </div>
                                <#if manageAuthLv <=5 >
                                <label class="control-label">是否查询关注：</label>
                                <div class="controls">
                                    <input type="checkbox" name="followFlag" value="true" />查询关注消耗资源过多，除非有必要否则不要查询关注
                                </div>

                                </#if>
                            </form>
                    		<div class="control-group">
                                <label class="control-label"></label>
                                <div class="controls">
                                    <a href="javascript:findDetail()" class="btn btn-info btn-sm">查询</a>
                                </div>
                            </div>
                        </div>
                    </div>

                     <div class="well form-horizontal">
                         <div class='main-action' id="mainAction">
                         </div>
                     </div>
                </div>
            </div>
        </div>
    </div>
</div>
  <script>
    $(document).ready(function() {

	});
	
	function findDetail(){
        $.ajax({
            url : "${rc.contextPath}/admin/auth/detail",
            dataType : "json",
            data :  $("#searchForm").serialize(),
            type:'post',
            success:function(json){
                var data = json.data;
                if (data){
                    var m = $("#mainAction");
                    m.html("");
                    m.append($('<div class="control-group"><label class="control-label">uid</label><div class="controls">'+data.id+'</div></div>'));
                    m.append($('<div class="control-group"><label class="control-label">名字</label><div class="controls">'+data.name+'</div></div>'));
                    m.append($('<div class="control-group"><label class="control-label">等级</label><div class="controls">'+data.lv+'</div></div>'));
                    m.append($('<div class="control-group"><label class="control-label">196粉丝牌</label><div class="controls">'+data.fansLv+'</div></div>'));
                    m.append($('<div class="control-group"><label class="control-label">贵族</label><div class="controls">'+data.guizu+'</div></div>'));
                    var oldNames = data.oldNames;
                    var oldNamesUl = $("<ul></ul>")
                    for(var i = 0;i < oldNames.length; i++){
                        var oldName = oldNames[i];
                        oldNamesUl.append($("<li>"+oldName+"</li>"));
                    }
                    m.append($('<div class="control-group"><label class="control-label">曾用名</label><div class="controls">'+oldNamesUl.html()+'</div></div>'));

                    var badges = data.badges;
                    var badgesUl = $("<ul></ul>")
                    badgesUl.append($("<tr><td style='width:50px'>牌子</td><td style='width:50px;text-align: center'>等级</td><td>主播</td><tr/>"))
                    for(var i = 0;i < badges.length; i++){
                        var badge = badges[i];
                        var tr = $("<tr></tr>");
                        tr.append($("<td>"+badge.name+"</td>"));
                        tr.append($("<td style='text-align: center'>"+badge.lv+"</td>"));
                        tr.append($("<td>"+badge.owner+"</td>"));
                        badgesUl.append(tr);
                    }
                    m.append($('<div class="control-group"><label class="control-label">粉丝牌</label><table class="controls">'+badgesUl.html()+'</table></div>'));

                    var yubaFollows = data.yubaFollows;
                    if (yubaFollows.length > 0){
                        var followsUl = $("<ul></ul>")
                        var tr = $("<tr></tr>");
                        for(var i = 0;i < yubaFollows.length; i++){
                            var follow = yubaFollows[i];
                            if (follow.groupId == 588){
                                tr.append($("<td style='color:red;'>"+follow.groupName+"</td>"));
                            } else {
                                tr.append($("<td>"+follow.groupName+"</td>"));
                            }
                            if ((i+1)%10==0){
                                followsUl.append(tr);
                                tr = $("<tr></tr>");
                            } else if (i == yubaFollows.length - 1){
                                followsUl.append(tr);
                            }
                        }
                        m.append($('<div class="control-group"><label class="control-label">鱼吧关注</label><table class="controls">'+followsUl.html()+'</table></div>'));
                    }

                    var follows = data.follows;
                    if (follows.length > 0){
                        var followsUl = $("<ul></ul>")
                        var tr = $("<tr></tr>");
                        for(var i = 0;i < follows.length; i++){
                            var follow = follows[i];
                            if (follow.id == 20994953){
                                tr.append($("<td style='color:red;'>"+follow.name+"</td>"));
                            } else {
                                tr.append($("<td>"+follow.name+"</td>"));
                            }
                            if ((i+1)%10==0){
                                followsUl.append(tr);
                                tr = $("<tr></tr>");
                            } else if (i == follows.length - 1){
                                followsUl.append(tr);
                            }
                        }
                        m.append($('<div class="control-group"><label class="control-label">关注</label><table class="controls">'+followsUl.html()+'</table></div>'));
                    }
				}
            }
        });
	}
	
	function findChatmsgAjax(name,fuzzy){
		$.ajax({
			url : "${rc.contextPath}/admin/chatmsg/find",
	    	dataType : "json",
	    	data :  {"name":name,"fuzzy":fuzzy},
	    	type:'post',
	    	success:function(json){
	    		var data = json.data;
				$("#itemTable").html("");
	    		for (var i=0;i<data.length;i++){
	    			showChatmsg(data[i]);
	    		}
	    	}
		});
	}
	
var pattern = "\\[emot:(dy\\d{3})\\]";
var newStr = '<img src="https://shark.douyucdn.cn/app/douyu/res/page/room-normal/face/$1.png?v=20170626">';
var regExp = new RegExp(pattern,'gm');
function txtReplace(txt){
	return txt.replace(regExp,newStr);
}
	function showChatmsg(data){
		var tr = $('<tr></tr>')
		var td1 = $('<td style="width:130px">'+formatDate(data.time)+'</td>');
		var td2 = $('<td style="width:150px">'+data.name+'</td>');
		var td3 = $('<td style="">'+chatmsgReplace(data.txt)+'</td>');
		tr.append(td1).append(td2).append(td3);
		$("#itemTable").append(tr);
	}
	
	function  formatDate(now)   {      
		var now= new Date(now);     
		var year=now.getFullYear();     
		var month=now.getMonth()+1;     
		var date=now.getDate();     
		var hour=now.getHours();      
		var minute=now.getMinutes();     
		var second=now.getSeconds();      
		return  year+"-"+buling(month)+"-"+buling(date)+" "+buling(hour)+":"+buling(minute)+":"+buling(second); 
	}
	function buling(a){
		if (a < 10){
			return "0"+a;
		} else {
			return a;
		}
	}
	
		
   </script>
</body>
</html>